/**
 * 场景2
 * @description: 游戏开始
 * @author: HuiSir
 * @update: HuiSir(2019-6-17 18:30:37)
 */	
(function(window) {
	let Scene2 = window.Scene2 = function() {
		//当前场景
		myGame.curScene = 2
	}
	
	Scene2.prototype.update = function() {
		//更新
		myGame.bg.update()
		myGame.land.update()
		myGame.bird.update()
		//管子生成
		myGame.fno % myGame.pipeSpaceFno || new Pipe()
		//管子更新
		for (var i = 0; i < myGame.pipeArr.length; i++) {
			myGame.pipeArr[i].update()
			//分数更新
			if(!myGame.pipeArr[i].isAddScore){
				if(myGame.pipeArr[i].x+myGame.pipeArr[i].pipeWidth < myGame.bird.x){
					myGame.score++
					myGame.pipeArr[i].isAddScore = true	//管子是否已被记分（状态量）
				}
			}
		}
	}
	
	//渲染
	Scene2.prototype.render = function() {
		//渲染背景
		myGame.bg.render()
		//渲染大地
		myGame.land.render()
		//渲染小鸟
		myGame.bird.render()
		//渲染管道
		for (var i = 0; i < myGame.pipeArr.length; i++) {
			myGame.pipeArr[i].render()
		}
		//渲染分数
		let scoreLength = myGame.score.toString().length
		for (var i = 0; i < scoreLength; i++) {
			myGame.ctx.drawImage(myGame['font_'+myGame.score.toString()[i]],(myGame.c.width-scoreLength*30)/2 + i*30,myGame.c.height*0.2)
		}
	}
})(window)